// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.chimi.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.chimi.controller.request.QueryBarPresentReq;
import com.liuxinlong.modules.chimi.controller.request.UpdateBarPresentReq;
import com.liuxinlong.modules.chimi.service.BarPresentService;
import com.liuxinlong.modules.common.controller.request.BaseDeleteReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.entity.BarPresent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 论坛礼品管理控制层
 * 
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2022-07-28
 */
@RestController
@RequestMapping("/present")
public class BarPresentController {

	@Autowired
	private BarPresentService barPresentService;

	/**
	 * 分页查询礼品信息
	 * 
	 * @param req 请求信息
	 * @return 礼品信息列表
	 */
	@PostMapping("page")
//	@LogAnnotation(value ="分页查询",business = LogBusinessConstants.BAR_PRESENT,operateType = LogOperateConstants.OPERATE_QUERY)
	public BaseResp pagePresentInfo(@RequestBody QueryBarPresentReq req) {
		Map<String,Object> queryParam = new HashMap<>();
		queryParam.put("startNum",req.getStartNum());
		queryParam.put("pageSize",req.getPageSize());
		queryParam.put("name",req.getName());
		queryParam.put("status",req.getStatus());
		List<Map<String,Object>> dataList = barPresentService.pagePresent(queryParam);
		int total = barPresentService.getPresentCount(queryParam);
		BaseResp resp = new BaseResp();
		resp.setDataList(dataList);
		resp.setTotalNum(total);
		resp.setRetMessage("分页查询礼品信息成功");
		return resp;
	}

	/**
	 * 新增礼品
	 * 
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("add")
	@LogAnnotation(value ="新增礼品",business = LogBusinessConstants.BAR_PRESENT,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp addPresent(@RequestBody UpdateBarPresentReq req) {
		BarPresent barPresent = new BarPresent();
		barPresent.setSn(req.getSn());
		barPresent.setName(req.getName());
		barPresent.setType(req.getType());
		barPresent.setPointNum(req.getPointNum());
		barPresent.setPurpose(req.getPurpose());
		barPresent.setPrice(req.getPrice());
		barPresent.setNeedPoint(req.getNeedPoint());
		barPresent.setFloor(req.getFloor());
		barPresent.setTotalNum(req.getTotalNum());
		barPresent.setMaxHit(req.getMaxHit());
		barPresent.setPicture(req.getPicture());
		barPresent.setStatus(req.getStatus());
		barPresent.setRemark(req.getRemark());
		barPresentService.addPresent(barPresent);
		BaseResp resp = new BaseResp();
		resp.setRetMessage("新增礼品成功");
		return resp;
	}

	/**
	 * 修改礼品信息
	 * 
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("update")
	@LogAnnotation(value ="修改礼品信息",business = LogBusinessConstants.BAR_PRESENT,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp updatePresent(@RequestBody UpdateBarPresentReq req) {
		BarPresent barPresent = new BarPresent();
		barPresent.setId(req.getId());
		barPresent.setSn(req.getSn());
		barPresent.setName(req.getName());
		barPresent.setType(req.getType());
		barPresent.setPointNum(req.getPointNum());
		barPresent.setPurpose(req.getPurpose());
		barPresent.setPrice(req.getPrice());
		barPresent.setNeedPoint(req.getNeedPoint());
		barPresent.setFloor(req.getFloor());
		barPresent.setTotalNum(req.getTotalNum());
		barPresent.setMaxHit(req.getMaxHit());
		barPresent.setPicture(req.getPicture());
		barPresent.setStatus(req.getStatus());
		barPresent.setRemark(req.getRemark());
		barPresentService.updatePresent(barPresent);
		BaseResp resp = new BaseResp();
		resp.setRetMessage("修改礼品信息成功");
		return resp;
	}

	/**
	 * 删除礼品信息
	 * 
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("delete")
	@LogAnnotation(value ="删除礼品信息",business = LogBusinessConstants.BAR_PRESENT,operateType = LogOperateConstants.OPERATE_DELETE)
	public BaseResp deletePresent(@RequestBody BaseDeleteReq req) {
		barPresentService.deletePresent(req.getId());
		BaseResp resp = new BaseResp();
		resp.setRetMessage("删除礼品信息成功");
		return resp;
	}

	/**
	 * 修改礼品状态
	 *
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("status/update")
	@LogAnnotation(value ="修改礼品状态",business = LogBusinessConstants.BAR_PRESENT,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp updatePresentStatus(@RequestBody BaseDeleteReq req) {
		barPresentService.updatePresentStatus(req.getId());
		BaseResp resp = new BaseResp();
		resp.setRetMessage("修改礼品状态成功");
		return resp;
	}

	/**
	 * 查询可用礼品列表
	 *
	 * @return 礼品信息列表
	 */
	@GetMapping("available/query")
	public BaseResp queryAvailablePresent() {
		List<Map<String,Object>> dataList = barPresentService.queryAvailablePresent();
		BaseResp resp = new BaseResp();
		resp.setDataList(dataList);
		resp.setRetMessage("查询可用礼品列表成功");
		return resp;
	}

	/**
	 * 查询全部礼品列表
	 *
	 * @return 礼品信息列表
	 */
	@GetMapping("all/query")
	public BaseResp queryAllPresent() {
		List<Map<String,Object>> dataList = barPresentService.queryAllPresent();
		BaseResp resp = new BaseResp();
		resp.setDataList(dataList);
		resp.setRetMessage("查询全部礼品列表列表成功");
		return resp;
	}
}
